package com.briup.pts.service.impl;


import com.briup.pts.domain.bean.QuarantineRegistration;
import com.briup.pts.mapper.QuarantineMapper;
import com.briup.pts.service.QuarantineService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@RequiredArgsConstructor
@Service
public class QuarantineServiceImpl implements QuarantineService {
    private final QuarantineMapper mapper;

    @Override
    public PageInfo<QuarantineRegistration> pageQueryByCondition(String bQualified, String grMechanism, Integer pageNum, Integer pageSize) {
        // 使用过PageHelper开启分页
        try (Page<QuarantineRegistration> ignored = PageHelper.startPage(pageNum, pageSize)) {
            // 根据条件查询数据库中的数据
            List<QuarantineRegistration> quarantines = mapper.queryPage(bQualified,grMechanism);

            // 将查询的结果数据放入到PageInfo中返回
            return new PageInfo<>(quarantines);
        }
    }

    @Override
    public void saveOrUpdate(QuarantineRegistration quarantine) {
       if (quarantine.getGrId()==null){
           mapper.addQuarantine(quarantine);
       }else {
           mapper.updateQuarantine(quarantine);
       }
    }

    @Override
    public void deleteById(int grId) {
        mapper.deleteById(grId);
    }

    @Override
    public void deleteByIdAll(List<Integer> ids) {
        mapper.deleteByIdAll(ids);
    }
}
